package com.sulent.frame.file.impl;

import com.sulent.frame.file.FileServer;
import com.sulent.frame.file.dto.FileVo;
import com.sulent.frame.file.utils.NasSmbUtils;
import lombok.Data;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;

/**
 * @ClassName NasFileServer
 * @Description: TODO
 * @Author Submerge.
 * @Since 2024/11/7 17:28
 * @Version 1.0
 */
@Data
public class NasFileServer implements FileServer {

    private String username;
    private String password;
    private String host;
    private int port;
    private int timeout;
    private String shareName;//共享名称
    private String dirName;//目录名称

    public NasFileServer(String host,int port,String username,String password,int timeout){
        this.host=host;
        this.port = port;
        this.username=username;
        this.password=password;
        this.timeout=timeout;
    }


    @Override
    public void uploadFile(File file, String targetPath) {
        NasSmbUtils nasSmbUtils = new NasSmbUtils(this);
        try {
            nasSmbUtils.upload(targetPath,file.getName(),new FileInputStream(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

    @Override
    public File downloadFile(String sourceFilePath, String destinationPath) {
        NasSmbUtils nasSmbUtils = new NasSmbUtils(this);
        //return nasSmbUtils.download(sourceFilePath,sourceFilePath,new Object());
        return null;
    }

    @Override
    public List<FileVo> listFiles(String targetPath) {
        NasSmbUtils nasSmbUtils = new NasSmbUtils(this);
        nasSmbUtils.getFileInfoByPath(dirName,false);
        return null;
    }

    @Override
    public void close() throws Exception {
        System.out.println("nas file sever close");
    }
}
